package de.recipeminer.models.generic;

import com.google.common.collect.Maps;
import org.apache.log4j.Logger;

import java.util.Map;

public abstract class  AnnotatableObject {
    private static Logger logger = Logger.getLogger(AnnotatableObject.class);
    protected Map<String, Object> annotations = Maps.newHashMap();

    public String getAnnotation(String key) {
        Object value =  annotations.get(key);
        String ret;
        if(value instanceof String ) {
            ret = (String) value;
        } else {
            logger.warn("String access to non-String Annotation: " + key);
            ret = value.toString();
        }
        return ret;
    }

    public Object getAnnotationObject(String key) {
        return annotations.get(key);
    }

    public <E extends Enum> String getAnnotation(E key){
        return getAnnotation(key.name());
    }
    
    public <E extends Enum> Object getAnnotationObject(E key){
        return getAnnotationObject(key.name());
    }

    public Object setAnnotation(String key, Object value) {
        return annotations.put(key, value);
    }

    public <E extends Enum> Object setAnnotation(E key, Object value) {
        return annotations.put(key.name(), value);
    }
}
